//
// Created by xili on 2024/9/3 15:25.
// GO BIG OR GO HOME.
//
#include "leetcode.h"

class Solution {
public:
    int minCost(string colors, vector<int> &neededTime) {
        int ans = 0;
        int n = colors.size();
        int i = 0;
        while (i < n) {
            char c = colors[i];
            int mx = 0;
            int sum = 0;
            while (i < n && colors[i] == c) {
                mx = max(mx, neededTime[i]);
                sum += neededTime[i];
                i++;
            }
            ans += sum - mx;
        }
        return ans;
    }
};